package com.eling.elcms.basedoc.dao.hibernate;

import com.eling.elcms.basedoc.dao.IAdminDivisionDao;
import com.eling.elcms.basedoc.model.AdministrativeDivision;
import com.eling.elcms.core.dao.hibernate.GenericDaoHibernate;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AdminDivisionDaoHibernate extends GenericDaoHibernate<AdministrativeDivision, Long> implements IAdminDivisionDao {
    
	public AdminDivisionDaoHibernate() {
		super(AdministrativeDivision.class);
		
	}

	@Override
	public List<AdministrativeDivision> queryByParent(String parentCode) {
		if (StringUtils.isBlank(parentCode)) {
			parentCode = "";
		}
		String hql = "from AdministrativeDivision ad where ad.code like :parentCode";
		@SuppressWarnings("unchecked")
		List<AdministrativeDivision> ads = getSession().createQuery(hql).setParameter("parentCode", parentCode + "__").list();
		return ads;
	}
}
